nice_things/type/class.sh
Utility functions for implementing classes. This module is automatically imported by the class macro for use in the default private methods.
check_reference
Since 0.3.0 · Source
import "{ check_reference }" from nice_things/type/class.sh
Synopsischeck_reference <ref> [<caller_name>]
Configuration
–
Description
Check if <ref> looks like a reference to an object; abort on failure.
An optional second argument <caller_name> can be used to pass in the name of the calling function, to improve the error message.
Note
This function is used internally by all the default private methods of a class. Calling it directly is rarely necessary because most public methods will start by calling their private getter
<Class>_get_, in which case the reference has already been checked.
Options
–
Operands
<ref>: The value to check.<caller_name>: Optional name of the calling function.
Stdin
–
Stdout
–
Stderrlog_error.
Exit status
0: Successful completion.12: Invalid reference (abort).
Abort
Aborts on invalid reference.
Usage examples
NS__MyClass_method() {
check_reference "$1" MyClass_method
# Do something with "$1"
}
get_instance_id
Since 0.3.0 · Source
import "{ get_instance_id }" from nice_things/type/class.sh
Synopsisget_instance_id <ref> <out_var>
Configuration
–
Description
Get the instance id part of an object reference and assign it to a variable. The instance id is a unique identifier of the object instance and can be used as a portion of a variable name, as long as not the beginning of the name. This can be used to create object state.
Note
This is a low-level function used internally by the default private methods of a class. User code will rarely need this.
Options
–
Operands
<ref>: An object reference.<out_var>: Output variable; the result will be written to this variable.
Stdin
–
Stdout
–
Stderr
–
Exit status0: Successful completion.
Abort
–
Usage examples
NS__MyClass_method() {
check_reference "$1" MyClass_method
get_instance_id "$1" NS__instance_id
# Do something with "$NS__instance_id"
}